﻿using System;
using System.Threading.Tasks;
using Jinjia.Approve.IRepository;
using Jinjia.Approve.IService.JJFlow.Condition;
using JinJia.Core.Base.Exceptions;

namespace Jinjia.Approve.Service.JJFlow.Condition
{
    public class FxOrderShopFinancialCondition : IJJCondition
    {
        private readonly IErpaManualTradeRepository _erpaManualTradeRepository;
        private readonly IErpaBaseRepository _erpaBaseRepository;

        public FxOrderShopFinancialCondition(IErpaManualTradeRepository erpaManualTradeRepository, IErpaBaseRepository erpaBaseRepository)
        {
            _erpaManualTradeRepository = erpaManualTradeRepository;
            _erpaBaseRepository = erpaBaseRepository;
        }

        public async Task<bool> IsSatisfied(string biz_order_id, string depart_id = "0", string user_id = "0")
        {
            var order = await _erpaManualTradeRepository.GetById(Convert.ToInt32(biz_order_id));

            if (order == null)
            {
                throw new BusinessException("未找到订单信息！");
            }

            //校验当前订单的店铺是否需要客审
            var shop_no_list = await _erpaBaseRepository.GetValuesByCodeType("fx_shop_review");
            if (shop_no_list.Contains(order.shop_no))
            {
                return true;
            }

            return false;
        }
    }
}